package com.yfeng.common.dao;



import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * 参数类
 * 简单的封装了下，能提供一些自己的方法。
 * User: raoqn
 * Date: 2009-2-6
 * Time: 21:19:55
 */
public class Param {

    private final static Log log = LogFactory.getLog(Param.class);

    public static final int VALUE = 1;
    public static final int CONDITION = 2;
    Map<String, Object> params;

    public Param() {
        params = new LinkedHashMap<String, Object>();
    }

    public Param(String key, Object value) {
        params = new LinkedHashMap<String, Object>();
        params.put(key, value);
    }

    public Param(String key, Object value, int cond) {
        params = new LinkedHashMap<String, Object>();
        if (cond == VALUE) {
            this.params.put("value__" + key, value);
        } else if (cond == CONDITION) {
            this.params.put("cond__" + key, value);
        } else
            log.info("非法参数");
    }


    public void put(String key, Object value) {
        this.params.put(key, value);
    }

    public void put(String key, Object value, int cond) {
        if (cond == VALUE) {
            this.params.put("value__" + key, value);
        } else if (cond == CONDITION) {
            this.params.put("cond__" + key, value);
        } else
            log.info("非法参数");
    }

    public Object get(Object o) {
        return this.params.get(o);
    }

    public void remove(Object o) {
        this.params.remove(o);
    }

    public Boolean isContainsKey(Object key) {
        return this.params.containsKey(key);
    }

    public Boolean isContainsValue(Object v) {
        return this.params.containsValue(v);
    }

    public Set<String> keySet() {
        return this.params.keySet();
    }

    /**
     * 取第一个记录的KEY
     *
     * @return
     */
    public String getFirstKey() {

        if (!params.isEmpty()) {
            return params.keySet().iterator().next();
        } else
            return null;
    }

    public Boolean isEmpty() {
        return this.params.isEmpty();
    }

    public void clear()
    {
    	params.clear();
    }
    public Map toMap() {
        return params;
    }


}
